<?php 
	require "./include/common.inc.php";
	require "./include/uploads.func.php";
	require './include/thumb.func.php';   //缩略图

	$id = $_COOKIE['uid'];
	if( $_POST ){
		//接收并校验数据
		$data['age'] = $_POST['age']+0;

		//接收上传文件
		$path = ROOT.'/uploads/teacher/';
		$min_path = ROOT.'/uploads/min_teacher/';
		//print_r(ROOT);die;  D:/wamp/school
		//print_r(WEB);die;  http://www.school.org/
		$res = uploads('avatar',$path);
		// var_dump($res[1]);die;
		if( $res[0] ){
			$data['avatar'] = $res[1];
			thumb($res,50,0,true,$min_path.$data['avatar']);
		}

		$res = edit('teacher',$data,"id=$id");
		
		//print_r($path.$_POST['oldpic']);die;D:/wamp/school/uploads/student/2016/11/27/2016112714441960208.jpg

		if( $res ){
			if( file_exists($path.$_POST['oldpic']) ){
				unlink( $path.$_POST['oldpic'] );
			}
			if( file_exists($min_path.$_POST['oldpic']) ){
				unlink( $min_path.$_POST['oldpic'] );
			}
			showMsg('修改成功！','?');
		}else{
			showMsg('修改失败！');
		}
	}

	$sql = "select `id`,`name`,`avatar`,`sex`,`age`,`mobi`,`qq`,`email`,`descr` from `teacher` where `id` = '$id' ";
	$user = get_one($sql);
?>

<!DOCTYPE html>
<html>
<head>
	<title>个人中心</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- loading mui -->
	<link rel="stylesheet" type="text/css" href="css/mui.min.css">
	<!-- custorm style -->
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<script src="./js/placeImage.js"></script>
</head>
<body>
	<!-- 导航栏 -->
	<header id="header" class="mui-bar mui-bar-nav">
		<h1 class="mui-title">奇猿学生课程管理系统</h1>
		<a class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left" href="javascript:history.go(-1)"><span class="mui-icon mui-icon-left-nav"></span></a>
		<a class="mui-icon mui-icon-bars mui-pull-right" href="#topPopover"></a>
	</header>
	<!-- 右上角弹出菜单 -->
	<div id="topPopover" class="mui-popover">
		<div class="mui-popover-arrow"></div>
		<div class="mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell"><a href="teacher_index.php">首页</a>
					</li>
					<li class="mui-table-view-cell"><a href="query.html">我要查询</a>
					</li>
					<li class="mui-table-view-cell"><a href="rate.php">我要评价</a>
					</li>
					<li class="mui-table-view-cell"><a href="enroll.php">我要选课</a>
					</li>
					<li class="mui-table-view-cell"><a href="teacher_message.php">我要留言</a>
					</li>
					<li class="mui-table-view-cell"><a href="login.php">退出登录</a>
					</li>

				</ul>
			</div>
		</div>
	</div>
	<!-- 主内容部分 -->
	<div class="content">
		<section class="xueqi">
			<div class="class">
				<label id="classResult">个人中心</label>
			</div>
		</section>
		<form enctype="multipart/form-data" method="post" name"form1">
			<section class="personData">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell mui-media">
						<div class="mui-navigate-right uploads">
							<img id="previ ew" name="pic" class="mui-media-object mui-pull-left head-img" src="<?=WEB.'uploads/teacher/'.$user['avatar']; ?>">
							<label class="name"><?=$user['name']; ?></label>
							<input type="file" name="avatar" id="f" onchange="change()" style="display:none" />
							<input type="hidden" name="oldpic" value="<?=$user['avatar']; ?>">
						</div>
					</li>
				</ul>
				<a style="position:absolute;left:20px;">头像预览</a><p><img id="preview" alt="" name="pic" style="width:100px;height:100px;margin: 0 auto;" /></p>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<a>编号<span class="mui-pull-right"><input type="text" name="id" value="<?=$user['id']; ?>"></span></a>
					</li>
					<li class="mui-table-view-cell">
						<a>性别<span class="mui-pull-right"><input type="text" name="sex" value="<?=$user['sex']==1?'男':'女'; ?>"></span></a>
					</li> 				
					<li class="mui-table-view-cell">
						<a>QQ<span class="mui-pull-right"><input type="text" name="qq" value="<?=$user['qq']; ?>"></span></a>
					</li>
					<li class="mui-table-view-cell">
						<a>手机号<span class="mui-pull-right"><input type="text" name="mobi" value="<?=$user['mobi']; ?>"></span></a>
					</li>
					<li class="mui-table-view-cell">
						<a>邮箱地址<span class="mui-pull-right"><input type="text" name="email" value="<?=$user['email']; ?>"></span></a>
					</li>
					<li class="mui-table-view-cell">
						<a>个性签名<span class="mui-pull-right"><input type="text" name="descr" value="<?=$user['descr']; ?>"></span></a>
					</li>
					<li>
						<input type="submit" value="保存">
					</li>
				</ul>
			</section>
		</form>
	</div>
	<script src="js/mui.min.js"></script>
	<script>
		var btn = document.querySelector( '.mui-navigate-right' );
		var avatar = document.querySelector( 'input[name=avatar]' );
		btn.addEventListener('click',function(){
			avatar.click();
		});
	</script>
</body>
</html>